package org.jeecg.modules.report.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.SsoUtil;
import org.jeecg.common.util.StringUtils;
import org.jeecg.modules.report.entity.ReportConfig;
import org.jeecg.modules.report.entity.ReportConfigInfo;
import org.jeecg.modules.report.entity.ReportConfigVideo;
import org.jeecg.modules.report.service.*;
import org.jeecg.modules.report.vo.*;
import org.jeecg.modules.system.entity.SysDepart;
import org.jeecg.modules.system.service.ISysDepartService;
import org.jeecg.modules.system.service.ISysDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
* @Description: 小区概况
* @Author: jeecg-boot
* @Date:   2019-08-14
* @Version: V1.0
*/
@Slf4j
@Api(tags="战图")
@RestController
@RequestMapping("/b/station")
public class StationController {
   @Autowired
   private IBaseDataService baseDataService;
   @Autowired
   private ICarDataService carDataService;
   @Autowired
   private IProjectDataService projectDataService;
   @Autowired
   private IComplainDataService complainDataService;
   @Autowired
   private IReportConfigService reportConfigService;
   @Autowired
   private IEquipDataService equipDataService;
   @Autowired
   private IChargeDataService chargeDataService;
   @Autowired
   private ISysDepartService sysDepartService;
   @Autowired
   private IReportConfigVideoService reportConfigVideoService;
   @Autowired
   private ISysDictService dictService;
   @Autowired
   private IWebSocketSendService webSocketSendService;
   @Autowired
   private RestTemplate restTemplate;
   @Autowired
   private RedisUtil redisUtil;




   @AutoLog(value = "战图列表")
   @ApiOperation(value = "战图列表", notes = "战图列表")
   @GetMapping(value = "/app/list")
   public Result app(String type,HttpServletRequest request){
      log.info(type);
      return Result.ok();
   }
   //TODO
   @GetMapping(value = "/getRepairReport")
    public Result getRepairReport(String projectId){
      RepairReport repairReport = projectDataService.getRepairReport(projectId,"1");
      System.out.println(repairReport);
      return Result.ok(repairReport);
    }


   @AutoLog(value = "事件警报")
   @ApiOperation(value = "事件警报", notes = "事件警报")
   @GetMapping(value = "/eventInfo")
   public Result<EquipEventReport> eventInfo(StationBean stationBean,HttpServletRequest request){
      if (StringUtils.isNotBlank(stationBean.getProjectId())){  //小区
         try {
            Result<EquipEventReport> equipEventReportResult = equipDataService.findEventInfoByProject(stationBean.getProjectId(), CommonConstant.EVENT_WARNING_MIDDLE, CommonConstant.EVENT_WARNING_MAX, stationBean.getTenantId());
            if(equipEventReportResult.isSuccess()){
               for (EquipEventInfo info: equipEventReportResult.getResult().getEventInfoList()){
                  info.setWarningLevel_dictText(dictService.queryDictTextByKey("warning_level",info.getWarningLevel()));
               }
            }
            // String str = webSocketSendService.apiSend("e9ca23d68d884d4ebb19d07889727dae","equipEventInfo");
//            log.info("str",str);
            return equipEventReportResult;
         }catch (Exception e){
            log.error("事件警报API调用异常",e);
            return Result.error("事件警报API调用异常");
         }
      }
      return Result.ok();
   }

   @AutoLog(value = "设备分类状态统计")
   @ApiOperation(value = "设备分类状态统计", notes = "设备分类状态统计")
   @GetMapping(value = "/findEquipSortStatus")
   public Result findEquipSortStatus(StationBean stationBean){
      List<ItemDetail> itemDetailList = new LinkedList<ItemDetail>();
      sortStatus(stationBean, itemDetailList);
      return Result.ok(itemDetailList);
   }

   @AutoLog(value = "智能设备战图头部信息")
   @ApiOperation(value = "智能设备战图头部基础信息", notes = "智能设备战图头部基础信息")
   @GetMapping(value = "/getSmartDeviceHead")
   public Result<SmartDeviceHead> getSmartDeviceHead(StationBean stationBean){
      if (StringUtils.isNotBlank(stationBean.getProjectId())){
         SmartDeviceHead smartDeviceHead = new SmartDeviceHead();
         try{
            //设备总数
            Result<List<EquipStatusReport>> equipStatusRes = equipDataService.findStatusByProjectAndSort(stationBean.getProjectId(),"1",stationBean.getTenantId());
            BigDecimal total = BigDecimal.ZERO;
            BigDecimal normalNum = BigDecimal.ZERO;
            BigDecimal abNormalNum = BigDecimal.ZERO;
            if (equipStatusRes.isSuccess()){
               for (EquipStatusReport statusReport: equipStatusRes.getResult()){
                  BigDecimal tempNum = new BigDecimal(statusReport.getStatusNum());
                  total = total.add(tempNum);
                  if (CommonConstant.EQUIP_STATUS_NORMAL.equals(statusReport.getEquipStatus())){
                     normalNum = normalNum.add(tempNum);
                  } else {
                     abNormalNum = abNormalNum.add(tempNum);
                  }
               }
               BigDecimal abNormalRate = BigDecimal.ZERO;
               if (total.compareTo(BigDecimal.ZERO) != 0){
                  abNormalRate = abNormalNum.multiply(new BigDecimal(100)).divide(total,1,BigDecimal.ROUND_HALF_UP);
               }
               smartDeviceHead.setEquipTotal(total.toString());
               smartDeviceHead.setNormalTotal(normalNum.toString());
               smartDeviceHead.setAbNormalRate(abNormalRate.toString() + "%");
            } else {
               smartDeviceHead.setAbNormalRate("-");
               smartDeviceHead.setEquipTotal("-");
               smartDeviceHead.setNormalTotal("-");
            }
         }catch (Exception e){
            smartDeviceHead.setAbNormalRate("-");
            smartDeviceHead.setEquipTotal("-");
            smartDeviceHead.setNormalTotal("-");
            log.error("设备分类状态数API调用异常",e);
         }
         BaseProject baseProject =  baseDataService.getProjectById(stationBean.getProjectId(),stationBean.getTenantId());
         if (baseProject != null){
            smartDeviceHead.setRoomNum(baseProject.getRoomNum() + "户");
         } else {
            smartDeviceHead.setRoomNum("-");
         }
         //项目个数
         smartDeviceHead.setProjectNum(1);
         return Result.ok(smartDeviceHead);
      }
      return Result.ok();
   }


   @AutoLog(value = "智能设备战图中心第一部分")
   @ApiOperation(value = "智能设备战图中心第一部分", notes = "智能设备战图中心第一部分")
   @GetMapping(value = "/getSmartDeviceCenterOne")
   public Result<SmartDeviceCenterOne> getSmartDeviceCenterOne(StationBean stationBean){
      if (StringUtils.isNotBlank(stationBean.getProjectId())){  //项目级
         //消防设备
         try{
            Result<SmartDeviceCenterOne> res = equipDataService.getSmartDeviceCenter(stationBean.getProjectId(),stationBean.getTopSystem(),stationBean.getTenantId());
            return res;
         }catch (Exception e){
            log.error(e.getMessage(),e);
            return Result.error(e.getMessage());
         }
      } else if (StringUtils.isNotBlank(stationBean.getDepartId())){  //公司级

      }
      return Result.ok();
   }

   @AutoLog(value = "智能设备战图中心第一部分右侧排序")
   @ApiOperation(value = "智能设备战图中心第一部分右侧排序", notes = "智能设备战图中心第一部分右侧排序")
   @GetMapping(value = "/getSmartDeviceCenterRank")
   public Result<RankData> getSmartDeviceCenterRank(StationBean stationBean){
      if (StringUtils.isNotBlank(stationBean.getProjectId())){  //项目级
         try{
            Result<List<EventProcessStatus>> res = equipDataService.findUnProcessByProjectAndSystem(stationBean.getProjectId(),"消防系统",stationBean.getTenantId());
            List<String> nameList = new LinkedList<>();
            List<Integer> numList = new LinkedList<>();
            RankData rankData = new RankData();
            if (res.isSuccess()){
               List<EventProcessStatus> processStatusList = res.getResult();
               for (int i=0; i<processStatusList.size() && i<8; i++){
                  nameList.add(processStatusList.get(i).getEventSortName());
                  numList.add(processStatusList.get(i).getProcessNum());
               }
               rankData.setEventSortNum(processStatusList.size());
            }
            rankData.setNameList(nameList);
            rankData.setNumList(numList);
            return Result.ok(rankData);
         }catch (Exception e){
            log.error(e.getMessage(),e);
            return Result.error(e.getMessage());
         }
      } else if (StringUtils.isNotBlank(stationBean.getDepartId())){

      }
      return Result.ok();
   }


   /**
    * 自动生产战图
    * @return
    */
   @AutoLog(value = "智能设备战图中心第一部分右侧排序")
   @ApiOperation(value = "智能设备战图中心第一部分右侧排序", notes = "智能设备战图中心第一部分右侧排序")
   @GetMapping(value = "/autoCreate")
   public Result autoCreate(){
      List<ReportConfig> existList = reportConfigService.findAll();
      Map<String,ReportConfig> departExistMap = new HashMap<>();
      Map<String,ReportConfig> projectExistMap = new HashMap<>();
      for(ReportConfig config:existList){
         if (StringUtils.isNotBlank(config.getDepartId())){
            if (StringUtils.isNotBlank(config.getProjectId())){
               projectExistMap.put(config.getProjectId() + "_" + config.getReportType(),config);
            } else {
               departExistMap.put(config.getDepartId() + "_" + config.getReportType(),config);
            }
         } else {
            projectExistMap.put(config.getProjectId() + "_" + config.getReportType(),config);
         }
      }
      List<ReportConfig> addList = new ArrayList<ReportConfig>();
      List<SysDepart> departList =  sysDepartService.findAll();
      for (SysDepart sysDepart:departList){
         if (CommonConstant.DEPART_PROPERTY_DEPARTMENT.equals(sysDepart.getDepartProperty())) continue;
         String key = sysDepart.getId() + "_" + CommonConstant.REPORT_TYPE_2;
         if (departExistMap.get(key) != null) continue;
         ReportConfig reportConfig = new ReportConfig();
         reportConfig.setReportType(CommonConstant.REPORT_TYPE_2);
         reportConfig.setDepartId(sysDepart.getId());
         reportConfig.setTenantId(sysDepart.getTenantId());
         reportConfig.setTitle(sysDepart.getDepartName());
         reportConfig.setImageUrl("https://cimpicture.oss-cn-shanghai.aliyuncs.com/picture/20190820165017.png");
         addList.add(reportConfig);
      }
      List<BaseProject> projectList = baseDataService.findProjectAll();
      for (BaseProject baseProject:projectList){
         String key = baseProject.getId() + "_" + CommonConstant.REPORT_TYPE_1;
         if (projectExistMap.get(key) == null){
            ReportConfig reportConfig = new ReportConfig();
            reportConfig.setReportType(CommonConstant.REPORT_TYPE_1);
            reportConfig.setDepartId(baseProject.getDepartId());
            reportConfig.setProjectId(baseProject.getId());
            reportConfig.setTenantId(baseProject.getTenantId());
            reportConfig.setTitle(baseProject.getName());
            reportConfig.setImageUrl("https://cimpicture.oss-cn-shanghai.aliyuncs.com/picture/20190820165007.png");
            addList.add(reportConfig);
         }
         key = baseProject.getId() + "_" + CommonConstant.REPORT_TYPE_2;
         if (projectExistMap.get(key) == null){
            ReportConfig reportConfig = new ReportConfig();
            reportConfig.setReportType(CommonConstant.REPORT_TYPE_2);
            reportConfig.setDepartId(baseProject.getDepartId());
            reportConfig.setProjectId(baseProject.getId());
            reportConfig.setTenantId(baseProject.getTenantId());
            reportConfig.setTitle(baseProject.getName());
            reportConfig.setImageUrl("https://cimpicture.oss-cn-shanghai.aliyuncs.com/picture/20190820165017.png");
            addList.add(reportConfig);
         }
      }
      try{
         if (addList.size() > 0){
            int res = reportConfigService.saveBatch(addList);
            System.out.println(res);
            return Result.ok("处理成功,新增" + res + "条");
         } else {
            return Result.ok("处理成功,无增量变化");
         }
      }catch (Exception e){
         log.error(e.getMessage(),e);
         return Result.error("自动生成异常" + e.getMessage());
      }
   }


   /**
     * 分页列表查询
    * @param request
    * @return
    */
   @AutoLog(value = "战图列表")
   @ApiOperation(value = "战图列表", notes = "战图列表")
   @GetMapping(value = "/list")
   public Result list(HttpServletRequest request,StationBean params) throws ParseException {
      LoginUser user = SsoUtil.getLoginUser();
      log.info("" + user.getTenantId());
      List<ReportConfig> reportConfigList = reportConfigService.findListByUser(params);
      System.out.println(1);
      return Result.ok(reportConfigList);
   }

   @AutoLog(value = "战图详细页")
   @ApiOperation(value = "战图详细页", notes = "战图详细页")
   @GetMapping(value = "/info")
   public Result info(StationBean stationBean,HttpServletRequest request){
      ProjectView projectView = new ProjectView();
      List<ItemDetail> itemDetailList = new LinkedList<ItemDetail>();
      projectView.setItemDetailList(itemDetailList);
      if ("小区概况".equals(stationBean.getReportType())){
         if (StringUtils.isBlank(stationBean.getProjectId())){
            return Result.error("请选择需要显示的小区");
         }
         ItemDetail itemDetail1 = new ItemDetail();//社区基本情况
         itemDetail1.setTitle("社区基本情况");
         itemDetail1.setDesc1("建筑面积");
         itemDetail1.setDesc2("户数");
         itemDetail1.setDesc3("业主数");
         BaseProject baseProject =  baseDataService.getProjectById(stationBean.getProjectId(),stationBean.getTenantId());
         if (baseProject != null){
            projectView.setProjectId(stationBean.getProjectId());
            projectView.setProjectName(baseProject.getName());
            String buildArea = StringUtils.isNotBlank(baseProject.getBuildArea())?baseProject.getBuildArea():"-";
            itemDetail1.setDetail1(buildArea + "m²");
            itemDetail1.setDetail2(baseProject.getRoomNum());
            itemDetail1.setDetail3(baseProject.getCusNum());
            itemDetailList.add(itemDetail1);
         } else {
            return Result.error("所选小区系统中未查询到");
         }
         //车场概况
         ItemDetail itemDetail2 = new ItemDetail();
         itemDetail2.setTitle("车场概况");
         itemDetail2.setDesc1("车位总数");
         itemDetail2.setDesc2("空闲车位");
         itemDetail2.setDesc3("空闲率");
         try{
            Result<List<BaseParkInfo>> resultCar =  carDataService.getBaseParkInfo(stationBean.getProjectId(),stationBean.getTenantId());
            if (resultCar.isSuccess()) {
               List<BaseParkInfo> baseParkInfoList = resultCar.getResult();
               BigDecimal carBitNumSum = BigDecimal.ZERO;
               BigDecimal spaceBitNumSum = BigDecimal.ZERO;
               for (BaseParkInfo baseParkInfo:baseParkInfoList){
                  BigDecimal carBitNum = BigDecimal.ZERO;
                  if (baseParkInfo.getCarbitnum()!=null){
                     carBitNum = new BigDecimal(baseParkInfo.getCarbitnum());
                  }
                  BigDecimal spaceBitNum = BigDecimal.ZERO;
                  if (baseParkInfo.getSpacebitnum()!=null){
                     spaceBitNum = new BigDecimal(baseParkInfo.getSpacebitnum());
                  }
                  carBitNumSum = carBitNumSum.add(carBitNum);
                  spaceBitNumSum = spaceBitNumSum.add(spaceBitNum);
               }
               if (carBitNumSum.compareTo(BigDecimal.ZERO) != 0){
                  BigDecimal percent = spaceBitNumSum.multiply(new BigDecimal(100)).divide(carBitNumSum,1,BigDecimal.ROUND_HALF_UP);
                  itemDetail2.setDetail3(percent + "%");
                  itemDetail2.setDetail1(carBitNumSum.toString());
                  itemDetail2.setDetail2(spaceBitNumSum.toString());
               }
            } else{
               itemDetail2.setDetail1("0");
               itemDetail2.setDetail2("0");
               itemDetail2.setDetail3("0");
            }
         } catch (Exception e){
            log.error("车场概况异常",e);
            itemDetail2.setDetail1("-");
            itemDetail2.setDetail2("-");
            itemDetail2.setDetail3("-");
         }
         itemDetailList.add(itemDetail2);
         //本年度物业收缴金额
         ItemDetail itemDetail3 = new ItemDetail();
         itemDetail3.setTitle("本年度物业收缴金额(单位:元)");
         itemDetail3.setDesc1("应缴金额");
         itemDetail3.setDesc2("已缴金额");
         itemDetail3.setDesc3("收缴率");
         try{
            Result<ChargeCollect> resultCharge =  chargeDataService.getCollect(String.valueOf(DateUtils.getYear()),stationBean.getProjectId(),stationBean.getTenantId());
            if (resultCharge.isSuccess()){
               itemDetail3.setDetail1(resultCharge.getResult().getYearShouldMoney().toString());
               itemDetail3.setDetail2(resultCharge.getResult().getYearRealMoney().toString());
               itemDetail3.setDetail3(resultCharge.getResult().getYearCollect().toString() + "%");
            }
         }catch (Exception e){
            log.error("车场收缴金额Api接口调用异常",e);
            itemDetail3.setDetail1("-");
            itemDetail3.setDetail2("-");
            itemDetail3.setDetail3("-");
         }
         itemDetailList.add(itemDetail3);
         //本年度车场收缴金额
         ItemDetail itemDetail4 = new ItemDetail();
         itemDetail4.setTitle("本年度车场收缴金额(单位:元)");
         itemDetail4.setDesc1("固定车位");
         itemDetail4.setDesc2("临停收费");
         itemDetail4.setDesc3("总金额");
         try{
            Result<List<CarStatisticsGather>> resultCar =  carDataService.getParkFeeStatics(stationBean.getProjectId(),String.valueOf(DateUtils.getYear()),stationBean.getTenantId());
            if (resultCar.isSuccess()) {
               List<CarStatisticsGather> parkFeeStaticsList = resultCar.getResult();
               BigDecimal realAmountSum = BigDecimal.ZERO;
               BigDecimal tempAmountSum = BigDecimal.ZERO;
               BigDecimal cardAmountSum = BigDecimal.ZERO;
               for (CarStatisticsGather parkFee:parkFeeStaticsList){
                  BigDecimal tempAmount = parkFee.getTempAmount();  //线下临停金额
                  BigDecimal onlineTempAmount = parkFee.getOnlinetempAmount(); //线上临停金额
                  BigDecimal monthCardExtendAmount = parkFee.getMonthcardextendAmount(); //线下月卡金额
                  BigDecimal onlineMonthCardExtendAmount = parkFee.getOnlinemonthcardextendAmount();  //线上月卡金额
                  BigDecimal realAmount = parkFee.getRealAmount(); //实收总额
                  tempAmountSum = tempAmountSum.add(tempAmount).add(onlineTempAmount);
                  cardAmountSum = cardAmountSum.add(monthCardExtendAmount).add(onlineMonthCardExtendAmount);
                  realAmountSum = realAmountSum.add(realAmount);
               }
               itemDetail4.setDetail1(cardAmountSum.setScale(0).toString());
               itemDetail4.setDetail2(tempAmountSum.setScale(0).toString());
               itemDetail4.setDetail3(realAmountSum.setScale(0).toString());
            } else{
               itemDetail4.setDetail1("0");
               itemDetail4.setDetail2("0");
               itemDetail4.setDetail3("0");
            }
         } catch (Exception e){
            log.error("车场收缴金额异常",e);
            itemDetail4.setDetail1("-");
            itemDetail4.setDetail2("-");
            itemDetail4.setDetail3("-");
         }
         itemDetailList.add(itemDetail4);
         //报修服务
         ItemDetail itemDetail5 = new ItemDetail();
         itemDetail5.setTitle("报修服务");
         itemDetail5.setDesc1("报修总数");
         itemDetail5.setDesc2("已维修数");
         itemDetail5.setDesc3("维修完成率");
         try{
            RepairReport repairReport = projectDataService.getRepairReport(stationBean.getProjectId(),stationBean.getTenantId());
            itemDetail5.setDetail1(repairReport.getTotal().toString());
            itemDetail5.setDetail2(repairReport.getCompleteNum().toString());
            itemDetail5.setDetail3(repairReport.getPercent().toString() + "%");
         }catch (Exception e){
            itemDetail5.setDetail1("-");
            itemDetail5.setDetail2("-");
            itemDetail5.setDetail3("-");
         }
         itemDetailList.add(itemDetail5);

         //投诉处理
         ItemDetail itemDetail6 = new ItemDetail();
         itemDetail6.setTitle("投诉处理");
         itemDetail6.setDesc1("投诉总数");
         itemDetail6.setDesc2("已处理数");
         itemDetail6.setDesc3("处理率");
         try{
            ComplainReport complainReport = complainDataService.getComplainReport(stationBean.getProjectId(),stationBean.getTenantId());
            itemDetail6.setDetail1(complainReport.getTotal().toString());
            itemDetail6.setDetail2(complainReport.getCompleteNum().toString());
            itemDetail6.setDetail3(complainReport.getPercent().toString() + "%");
         }catch (Exception e){
            log.error("投诉异常",e.fillInStackTrace());
            itemDetail6.setDetail1("-");
            itemDetail6.setDetail2("-");
            itemDetail6.setDetail3("-");
         }
         itemDetailList.add(itemDetail6);

         //巡检任务
         ItemDetail itemDetail7 = new ItemDetail();
         itemDetail7.setTitle("每日巡检任务");
         itemDetail7.setDesc1("客服任务数");
         itemDetail7.setDesc2("环境任务数");
         itemDetail7.setDesc3("秩序任务数");
         itemDetail7.setDetail1("-");
         itemDetail7.setDetail2("-");
         itemDetail7.setDetail3("-");
         itemDetailList.add(itemDetail7);

         //设备报警
         ItemDetail itemDetail8 = new ItemDetail();
         itemDetail8.setTitle("设备报警");
         itemDetail8.setDesc1("严重报警数");
         itemDetail8.setDesc2("中度报警数");
         itemDetail8.setDesc3("轻度报警数");
         try {
            Result<List<EquipEventInfoSum>> result = equipDataService.findEventInfoSumByProject(stationBean.getProjectId(), "10,20,30",null,stationBean.getTenantId());
            if (result.isSuccess()){
               Map<Integer,EquipEventInfoSum> map = result.getResult().stream().collect(Collectors.toMap(EquipEventInfoSum::getWarningLevel, Function.identity()));
               itemDetail8.setDetail1(map.get(CommonConstant.EVENT_WARNING_MAX) != null ? map.get(CommonConstant.EVENT_WARNING_MAX).getInfoSum().toString():"0");
               itemDetail8.setDetail2(map.get(CommonConstant.EVENT_WARNING_MIDDLE) != null ? map.get(CommonConstant.EVENT_WARNING_MIDDLE).getInfoSum().toString():"0");
               itemDetail8.setDetail3(map.get(CommonConstant.EVENT_WARNING_MIN) != null ? map.get(CommonConstant.EVENT_WARNING_MIN).getInfoSum().toString():"0");
            } else {
               itemDetail8.setDetail1("-");
               itemDetail8.setDetail2("-");
               itemDetail8.setDetail3("-");
            }
         }catch (Exception e){
            log.error("设施警报汇总Api调用异常",e);
            itemDetail8.setDetail1("-");
            itemDetail8.setDetail2("-");
            itemDetail8.setDetail3("-");
         }
         itemDetailList.add(itemDetail8);
         sortStatus(stationBean, itemDetailList);

         //监控信息
         List<ReportConfigVideo> itemVideoList = reportConfigVideoService.selectByMainId(stationBean.getId());
         for (ReportConfigVideo reportConfigVideo:itemVideoList){
            //TODO 需动态获取
//            reportConfigVideo.setUrl("rtmp://rtmp01open.ys7.com/openlive/f01018a141094b7fa138b9d0b856507b.hd");
            reportConfigVideo.setUrl("http://alhlsgw.lechange.com:9001/LCO/3M036E8PAZ18462/15/0/20191008170635/dev_20191008170635_hkxz6a05i3f7p7za.m3u8");
         }
         projectView.setItemVideoList(itemVideoList);
         return Result.ok(projectView);
      } else {
        log.warn("不支持的战图类型");
      }
      return Result.ok();
   }

   //抽取方法
   private void sortStatus(StationBean stationBean, List<ItemDetail> itemDetailList) {
      List<ReportConfigInfo> reportConfigInfoList = reportConfigService.findConfigInfoByProjectId(stationBean.getReportType(),stationBean.getProjectId());
      if(reportConfigInfoList.size() > 0 ){
         for(ReportConfigInfo configInfo:reportConfigInfoList){
            ItemDetail itemDetail = new ItemDetail();
            itemDetail.setTitle(configInfo.getEquipSortName());
            itemDetail.setDesc1("正常数");
            itemDetail.setDesc2("异常数");
            itemDetail.setDesc3("异常率");
            try{
               Result<List<EquipStatusReport>> equipRes = equipDataService.findStatusByProjectAndSort(stationBean.getProjectId(),configInfo.getEquipSortId(),stationBean.getTenantId());
               if (equipRes.isSuccess()){
                  List<EquipStatusReport> reportList = equipRes.getResult();
                  BigDecimal normalNum = BigDecimal.ZERO;    //正常数
                  BigDecimal abNormalNum = BigDecimal.ZERO; //异常数
                  BigDecimal totalNum = BigDecimal.ZERO;
                  for (EquipStatusReport statusReport:reportList){
                     if (CommonConstant.EQUIP_STATUS_NORMAL.equals(statusReport.getEquipStatus())){
                        normalNum = normalNum.add(new BigDecimal(statusReport.getStatusNum()));
                     } else {
                        abNormalNum = abNormalNum.add(new BigDecimal(statusReport.getStatusNum()));
                     }
                     totalNum = totalNum.add(new BigDecimal(statusReport.getStatusNum()));
                  }
                  if (totalNum.compareTo(BigDecimal.ZERO) != 0){
                     BigDecimal lv = abNormalNum.multiply(new BigDecimal(100)).divide(totalNum,1,BigDecimal.ROUND_HALF_UP);
                     itemDetail.setDetail3(lv.toString() + "%");
                  } else {
                     itemDetail.setDetail3("-");
                  }
                  itemDetail.setDetail1(normalNum.toString());
                  itemDetail.setDetail2(abNormalNum.toString());
               } else {
                  itemDetail.setDetail1("0");
                  itemDetail.setDetail2("0");
                  itemDetail.setDetail3("0%");
               }
            }catch (Exception e){
               log.error("设施设备状态调用异常",e);
               itemDetail.setDetail1("-");
               itemDetail.setDetail2("-");
               itemDetail.setDetail3("-");
            }finally {
               itemDetailList.add(itemDetail);
            }
         }
      }
      for (int i=0 ;i<4-reportConfigInfoList.size();i++){
         ItemDetail itemDetail = new ItemDetail();
         itemDetail.setTitle("待配置分类");
         itemDetail.setDesc1("正常数");
         itemDetail.setDesc2("异常数");
         itemDetail.setDesc3("异常率");
         itemDetail.setDetail1("-");
         itemDetail.setDetail2("-");
         itemDetail.setDetail3("-");
         itemDetailList.add(itemDetail);
      }
   }



}
